home *** CD-ROM | disk | FTP | other *** search
/ Chip 1998 September / CHIP Eylül 1998.iso / Slackwar / docs / mini / Large-Disk < prev    next >
Text File  |  1996-08-03  |  19KB  |  399 lines

  1.   Large Disk mini-HOWTO
  2.   Andries Brouwer, aeb@cwi.nl
  3.   v1.0, 960626
  4.  
  5.   All about disk geometry and the 1024 cylinder limit for disks.
  6.  
  7.   1.  The problem
  8.  
  9.   Suppose you have a disk with more than 1024 cylinders.  Suppose
  10.   moreover that you have an operating system that uses the BIOS.  Then
  11.   you have a problem, because the usual INT13 BIOS interface to disk I/O
  12.   uses a 10-bit field for the cylinder on which the I/O is done, so that
  13.   cylinders 1024 and past are inaccessible.
  14.  
  15.   Fortunately, Linux does not use the BIOS, so there is no problem.
  16.  
  17.   Well, except for two things:
  18.  
  19.   (1) When you boot your system, Linux isn't running yet and cannot save
  20.   you from BIOS problems.  This has some consequences for LILO and
  21.   similar boot loaders.
  22.  
  23.   (2) It is necessary for all operating systems that use one disk to
  24.   agree on where the partitions are.  In other words, if you use both
  25.   Linux and, say, DOS on one disk, then both must interpret the
  26.   partition table in the same way.  This has some consequences for the
  27.   Linux kernel and for fdisk.
  28.  
  29.   Below a rather detailed description of all relevant details.  Note
  30.   that I used kernel version 2.0.8 source as a reference.  Other
  31.   versions may differ a bit.
  32.  
  33.   2.  Booting
  34.  
  35.   When the system is booted, the BIOS reads sector 0 (known as the MBR -
  36.   the Master Boot Record) from the first disk (or from floppy), and
  37.   jumps to the code found there - usually some bootstrap loader.  These
  38.   small bootstrap programs found there typically have no own disk
  39.   drivers and use BIOS services.  This means that a Linux kernel can
  40.   only be booted when it is entirely located within the first 1024
  41.   cylinders.
  42.  
  43.   This problem is very easily solved: make sure that the kernel (and
  44.   perhaps other files used during bootup, such as LILO map files) are
  45.   located on a partition that is entirely contained in the first 1024
  46.   cylinders of a disk that the BIOS can access - probably this means the
  47.   first or second disk.
  48.  
  49.   Another point is that the boot loader and the BIOS must agree as to
  50.   the disk geometry.  It may help to give LILO the `linear' option.
  51.   More details below.
  52.  
  53.   3.  Disk geometry and partitions
  54.  
  55.   If you have several operating systems on your disks, then each uses
  56.   one or more disk partitions.  A disagreement on where these partitions
  57.   are may have catastrophic consequences.
  58.  
  59.   The MBR contains a partition table describing where the (primary)
  60.   partitions are.  There are 4 table entries, for 4 primary partitions,
  61.   and each looks like
  62.  
  63.   struct partition {
  64.           char active;    /* 0x80: bootable, 0: not bootable */
  65.           char begin[3];  /* CHS for first sector */
  66.           char type;
  67.           char end[3];    /* CHS for last sector */
  68.           int start;      /* 32 bit sector number (counting from 0) */
  69.           int length;     /* 32 bit number of sectors */
  70.   };
  71.  
  72.   (where CHS stands for Cylinder/Head/Sector).
  73.  
  74.   Thus, this information is redundant: the location of a partition is
  75.   given both by the 24-bit begin and end fields, and by the 32-bit start
  76.   and length fields.
  77.  
  78.   Linux only uses the start and length fields, and can therefore handle
  79.   partitions of not more than 2^32 sectors, that is, partitions of at
  80.   most 2 TB.  That is two hundred times larger than the disks available
  81.   today, so maybe it will be enough for the next ten years or so.
  82.  
  83.   Unfortunately, the BIOS INT13 call uses CHS coded in three bytes, with
  84.   10 bits for the cylinder number, 8 bits for the head number, and 6
  85.   bits for the track sector number.  Possible cylinder numbers are
  86.   0-1023, possible head numbers are 0-255, and possible track sector
  87.   numbers are 1-63 (yes, sectors on a track are counted from 1, not 0).
  88.   With these 24 bits one can address 8455716864 bytes (7.875 GB), two
  89.   hundred times larger than the disks available in 1983.
  90.  
  91.   Even more unfortunately, the standard IDE interface allows 256
  92.   sectors/track, 65536 cylinders and 16 heads.  This in itself allows
  93.   access to 2^37 = 137438953472 bytes (128 GB), but combined with the
  94.   BIOS restriction to 63 sectors and 1024 cylinders only 528482304 bytes
  95.   (504 MB) remain addressable.
  96.  
  97.   This is not enough for present-day disks, and people resort to all
  98.   kinds of trickery, both in hardware and in software.
  99.  
  100.   4.  Translation and Disk Managers
  101.  
  102.   Nobody is interested in what the `real' geometry of a disk is.
  103.   Indeed, the number of sectors per track often is variable - there are
  104.   more sectors per track close to the outer rim of the disk - so there
  105.   is no `real' number of sectors per track.  For the user it is best to
  106.   regard a disk as just a linear array of sectors numbered 0, 1, ...,
  107.   and leave it to the controller to find out where a given sector lives
  108.   on the disk.
  109.  
  110.   This linear numbering is known as LBA.  The linear address belonging
  111.   to (c,h,s) for a disk with geometry (C,H,S) is c*H*S + h*S + (s-1).
  112.   All SCSI controllers speak LBA, and some IDE controllers do.
  113.  
  114.   If the BIOS converts the 24-bit (c,h,s) to LBA and feeds that to a
  115.   controller that understands LBA, then again 7.875 GB is addressable.
  116.   Not enough for all disks, but still an improvement.  Note that here
  117.   CHS, as used by the BIOS, no longer has any relation to `reality'.
  118.  
  119.   Something similar works when the controller doesn't speak LBA but the
  120.   BIOS knows about translation.  (In the setup this is often indicated
  121.   as `Large'.)  Now the BIOS will present a geometry (C',H',S') to the
  122.   operating system, and use (C,H,S) while talking to the disk
  123.   controller.  Usually S = S', C' = C/N and H' = H*N, where N is the
  124.   smallest power of two that will ensure C' <= 1024 (so that least
  125.   capacity is wasted by the rounding down in C' = C/N).  Again, this
  126.   allows access of up to 7.875 GB.
  127.  
  128.   If a BIOS does not know about `Large' or `LBA', then there are
  129.   software solutions around.  Disk Managers like OnTrack or EZ-Drive
  130.   replace the BIOS disk handling routines by their own.  Often this is
  131.   accomplished by having the disk manager code live in the MBR and
  132.   subsequent sectors (OnTrack calls this code DDO: Dynamic Drive
  133.   Overlay), so that it is booted before any other operating system.
  134.   That is why one may have problems when booting from a floppy when a
  135.   Disk Manager has been installed.
  136.  
  137.   The effect is more or less the same as with a translating BIOS - but
  138.   especially when running several different operating systems on the
  139.   same disk, disk managers can cause a lot of trouble.
  140.  
  141.   Linux does support OnTrack Disk Manager since version 1.3.14, and EZ-
  142.   Drive since version 1.3.29.  Some more details are given below.
  143.  
  144.   5.  Kernel disk translation for IDE disks
  145.  
  146.   If the Linux kernel detects the presence of some disk manager on an
  147.   IDE disk, it will try to remap the disk in the same way this disk
  148.   manager would have done, so that Linux sees the same disk partitioning
  149.   as for example DOS with OnTrack or EZ-Drive.  However, NO remapping is
  150.   done when a geometry was specified on the command line - so a
  151.   `hd=cyls,heads,secs' command line option might well kill compatibility
  152.   with a disk manager.
  153.  
  154.   The remapping is done by trying 4, 8, 16, 32, 64, 128, 255 heads
  155.   (keeping H*C constant) until either C <= 1024 or H = 255.
  156.  
  157.   The details are as follows - subsection headers are the strings
  158.   appearing in the corresponding boot messages.  Here and everywhere
  159.   else in this text partition types are given in hexadecimal.
  160.  
  161.   5.1.  EZD
  162.  
  163.   EZ-Drive is detected by the fact that the first primary partition has
  164.   type 55.  The geometry is remapped as described above, and the
  165.   partition table from sector 0 is discarded - instead the partition
  166.   table is read from sector 1.  Disk block numbers are not changed, but
  167.   writes to sector 0 are redirected to sector 1.  This behaviour can be
  168.   changed by recompiling the kernel with
  169.    #define FAKE_FDISK_FOR_EZDRIVE  0 in ide.c.
  170.  
  171.   5.2.  DM6:DDO
  172.  
  173.   OnTrack DiskManager (on the first disk) is detected by the fact that
  174.   the first primary partition has type 54.  The geometry is remapped as
  175.   described above and the entire disk is shifted by 63 sectors (so that
  176.   the old sector 63 becomes sector 0).  Afterwards a new MBR (with
  177.   partition table) is read from the new sector 0.  Of course this shift
  178.   is to make room for the DDO - that is why there is no shift on other
  179.   disks.
  180.  
  181.   5.3.  DM6:AUX
  182.  
  183.   OnTrack DiskManager (on other disks) is detected by the fact that the
  184.   first primary partition has type 51 or 53.  The geometry is remapped
  185.   as described above.
  186.  
  187.   5.4.  DM6:MBR
  188.  
  189.   An older version of OnTrack DiskManager is detected not by partition
  190.   type, but by signature.  (Test whether the offset found in bytes 2 and
  191.   3 of the MBR is not more than 430, and the short found at this offset
  192.   equals 0x55AA, and is followed by an odd byte.) Again the geometry is
  193.   remapped as above.
  194.  
  195.   5.5.  PTBL
  196.  
  197.   Finally, there is a test that tries to deduce a translation from the
  198.   start and end values of the primary partitions: If some partition has
  199.   start and end cylinder less than 256, and start and end sector number
  200.   1 and 63, respectively, and end heads 31, 63 or 127, then, since it is
  201.   customary to end partitions on a cylinder boundary, and since moreover
  202.   the IDE interface uses at most 16 heads, it is conjectured that a BIOS
  203.   translation is active, and the geometry is remapped to use 32, 64 or
  204.   128 heads, respectively.  (Maybe there is a flaw here, and genhd.c
  205.   should not have tested the high order two bits of the cylinder
  206.   number?)  However, no remapping is done when the current idea of the
  207.   geometry already has 63 sectors per track and at least as many heads
  208.   (since this probably means that a remapping was done already).
  209.  
  210.   6.  Consequences
  211.  
  212.   What does all of this mean?  For Linux users only one thing: that they
  213.   must make sure that LILO and fdisk use the right geometry where
  214.   `right' is defined for fdisk as the geometry used by the other
  215.   operating systems on the same disk, and for LILO as the geometry that
  216.   will enable successful interaction with the BIOS at boot time.
  217.   (Usually these two coincide.)
  218.  
  219.   How does fdisk know about the geometry?  It asks the kernel, using the
  220.   HDIO_GETGEO ioctl.  But the user can override the geometry
  221.   interactively or on the command line.
  222.  
  223.   How does LILO know about the geometry?  It asks the kernel, using the
  224.   HDIO_GETGEO ioctl.  But the user can override the geometry using the
  225.   `disk=' option.  One may also give the linear option to LILO, and it
  226.   will store LBA addresses instead of CHS addresses in its map file, and
  227.   find out of the geometry to use at boot time (by using INT 13 Function
  228.   8 to ask for the drive geometry).
  229.  
  230.   How does the kernel know what to answer?  Well, first of all, the user
  231.   may have specified an explicit geometry with a `hd=cyls,heads,secs'
  232.   command line option.  And otherwise the kernel will ask the hardware.
  233.  
  234.   6.1.  IDE details
  235.  
  236.   Let me elaborate.  The IDE driver has four sources for information
  237.   about the geometry.  The first (G_user) is the one specified by the
  238.   user on the command line.  The second (G_bios) is the BIOS Fixed Disk
  239.   Parameter Table (for first and second disk only) that is read on
  240.   system startup, before the switch to 32-bit mode.  The third (G_phys)
  241.   and fourth (G_log) are returned by the IDE controller as a response to
  242.   the IDENTIFY command - they are the `physical' and `current logical'
  243.   geometries.
  244.  
  245.   On the other hand, the driver needs two values for the geometry: on
  246.   the one hand G_fdisk, returned by a HDIO_GETGEO ioctl, and on the
  247.   other hand G_used, which is actually used for doing I/O.  Both G_fdisk
  248.   and G_used are initialized to G_user if given, to G_bios when this
  249.   information is present according to CMOS, and to to G_phys otherwise.
  250.   If G_log looks reasonable then G_used is set to that.  Otherwise, if
  251.   G_used is unreasonable and G_phys looks reasonable then G_used is set
  252.   to G_phys.  Here `reasonable' means that the number of heads is in the
  253.   range 1-16.
  254.  
  255.   To say this in other words: the command line overrides the BIOS, and
  256.   will determine what fdisk sees, but if it specifies a translated
  257.   geometry (with more than 16 heads), then for kernel I/O it will be
  258.   overridden by output of the IDENTIFY command.
  259.  
  260.   6.2.  SCSI details
  261.  
  262.   The situation for SCSI is slightly different, as the SCSI commands
  263.   already use logical block numbers, so a `geometry' is entirely
  264.   irrelevant for actual I/O.  However, the format of the partition table
  265.   is still the same, so fdisk has to invent some geometry, and also uses
  266.   HDIO_GETGEO here - indeed, fdisk does not distinguish between IDE and
  267.   SCSI disks.  As one can see from the detailed description below, the
  268.   various drivers each invent a somewhat different geometry.  Indeed,
  269.   one big mess.
  270.  
  271.   If you are not using DOS or so, then avoid all extended translation
  272.   settings, and just use 64 heads, 32 sectors per track (for a nice,
  273.   convenient 1 MB per cylinder), if possible, so that no problems arise
  274.   when you move the disk from one controller to another.  Some SCSI disk
  275.   drivers (aha152x, pas16, ppa, qlogicfas, qlogicisp) are so nervous
  276.   about DOS compatibility that they will not allow a Linux-only system
  277.   to use more than about 8 GB.  This is a bug.
  278.  
  279.   What is the real geometry?  The easiest answer is that there is no
  280.   such thing.  And if there were, you wouldn't want to know, and
  281.   certainly NEVER, EVER tell fdisk or LILO or the kernel about it.  It
  282.   is strictly a business between the SCSI controller and the disk.  Let
  283.   me repeat that: only silly people tell fdisk/LILO/kernel about the
  284.   true SCSI disk geometry.
  285.  
  286.   But if you are curious and insist, you might ask the disk itself.
  287.   There is the important command READ CAPACITY that will give the total
  288.   size of the disk, and there is the MODE SENSE command, that in the
  289.   Rigid Disk Drive Geometry Page (page 04) gives the number of cylinders
  290.   and heads (this is information that cannot be changed), and in the
  291.   Format Page (page 03) gives the number of bytes per sector, and
  292.   sectors per track.  This latter number is typically dependent upon the
  293.   notch, and the number of sectors per track varies - the outer tracks
  294.   have more sectors than the inner tracks.  The Linux program scsiinfo
  295.   will give this information.  There are many details and complications,
  296.   and it is clear that nobody (probably not even the operating system)
  297.   wants to use this information.  Moreover, as long as we are only
  298.   concerned about fdisk and LILO, one typically gets answers like
  299.   C/H/S=4476/27/171 - values that cannot be used by fdisk because the
  300.   partition table reserves only 10 resp. 8 resp. 6 bits for C/H/S.
  301.  
  302.   Then where does the kernel HDIO_GETGEO get its information from?
  303.   Well, either from the SCSI controller, or by making an educated guess.
  304.   Some drivers seem to think that we want to know `reality', but of
  305.   course we only want to know what the DOS or OS/2 FDISK (or Adaptec
  306.   AFDISK, etc) will use.
  307.  
  308.   Note that Linux fdisk needs the numbers H and S of heads and sectors
  309.   per track to convert LBA sector numbers into c/h/s addresses, but the
  310.   number C of cylinders does not play a role in this conversion.  Some
  311.   drivers use (C,H,S) = (1023,255,63) to signal that the drive capacity
  312.   is at least 1023*255*63 sectors.  This is unfortunate, since it does
  313.   not reveal the actual size, and will limit the users of most fdisk
  314.   versions to about 8 GB of their disks - a real limitation in these
  315.   days.
  316.  
  317.   In the description below, M denotes the total disk capacity, and C, H,
  318.   S the number of cylinders, heads and sectors per track.  It suffices
  319.   to give H, S if we regard C as defined by M / (H*S).
  320.  
  321.   By default, H=64, S=32.
  322.  
  323.      aha1740, dtc, g_NCR5380, t128, wd7000:
  324.         H=64, S=32.
  325.  
  326.      aha152x, pas16, ppa, qlogicfas, qlogicisp:
  327.         H=64, S=32 unless C > 1024, in which case H=255, S=63, C =
  328.         min(1023, M/(H*S)).  (Thus C is truncated, and H*S*C is not an
  329.         approximation to the disk capacity M.  This will confuse most
  330.         versions of fdisk.)  The ppa.c code uses M+1 instead of M and
  331.         says that due to a bug in sd.c M is off by 1.
  332.  
  333.      advansys:
  334.         H=64, S=32 unless C > 1024 and moreover the `> 1 GB' option in
  335.         the BIOS is enabled, in which case H=255, S=63.
  336.  
  337.      aha1542:
  338.         Ask the controller which of two possible translation schemes is
  339.         in use, and use either H=255, S=63 or H=64, S=32.  In the former
  340.         case there is a boot message "aha1542.c: Using extended bios
  341.         translation".
  342.  
  343.      aic7xxx:
  344.         H=64, S=32 unless C > 1024, and moreover either the "extended"
  345.         boot parameter was given, or the `extended' bit was set in the
  346.         SEEPROM or BIOS, in which case H=255, S=63.
  347.  
  348.      buslogic:
  349.         H=64, S=32 unless C >= 1024, and moreover extended translation
  350.         was enabled on the controller, in which case if M < 2^22 then
  351.         H=128, S=32; otherwise H=255, S=63.  However, after making this
  352.         choice for (C,H,S), the partition table is read, and if for one
  353.         of the three possibilities (H,S) = (64,32), (128,32), (255,63)
  354.         the value endH=H-1 is seen somewhere then that pair (H,S) is
  355.         used, and a boot message is printed "Adopting Geometry from
  356.         Partition Table".
  357.  
  358.      fdomain:
  359.         Find the geometry information in the BIOS Drive Parameter Table,
  360.         or read the partition table and use H=endH+1, S=endS for the
  361.         first partition, provided it is nonempty, or use H=64, S=32 for
  362.         M < 2^21 (1 GB), H=128, S=63 for M < 63*2^17 (3.9 GB) and H=255,
  363.         S=63 otherwise.
  364.  
  365.      in2000:
  366.         Use the first of (H,S) = (64,32), (64,63), (128,63), (255,63)
  367.         that will make C <= 1024.  In the last case, truncate C at 1023.
  368.  
  369.      seagate:
  370.         Read C,H,S from the disk.  (Horrors!)  If C or S is too large,
  371.         then put S=17, H=2 and double H until C <= 1024.  This means
  372.         that H will be set to 0 if M > 128*1024*17 (1.1 GB).  This is a
  373.         bug.
  374.  
  375.      ultrastor and u14_34f:
  376.         One of three mappings ((H,S) = (16,63), (64,32), (64,63)) is
  377.         used depending on the controller mapping mode.
  378.  
  379.   If the driver does not specify the geometry, we fall back on an edu¡
  380.   cated guess using the partition table, or using the total disk capac¡
  381.   ity.
  382.  
  383.   Look at the partition table.  Since by convention partitions end on a
  384.   cylinder boundary, we can, given end = (endC,endH,endS) for any
  385.   partition, just put H = endH+1 and S = endS.  (Recall that sectors are
  386.   counted from 1.)  More precisely, the following is done.  If there is
  387.   a nonempty partition, pick the partition with the largest beginC.  For
  388.   that partition, look at end+1, computed both by adding start and
  389.   length and by assuming that this partition ends on a cylinder
  390.   boundary.  If both values agree, or if endC = 1023 and start+length is
  391.   an integral multiple of (endH+1)*endS, then assume that this partition
  392.   really was aligned on a cylinder boundary, and put H = endH+1 and S =
  393.   endS.  If this fails, either because there are no partitions, or
  394.   because they have strange sizes, then look only at the disk capacity
  395.   M.  Algorithm: put H = M/(62*1024) (rounded up), S = M/(1024*H)
  396.   (rounded up), C = M/(H*S) (rounded down).  This has the effect of
  397.   producing a (C,H,S) with C at most 1024 and S at most 62.
  398.  
  399.